package com.yhb.utils;

import org.apache.http.util.TextUtils;

import java.util.regex.Pattern;

public class StringUtils extends me.edzh.spring.bootstrap.utils.StringUtils {
    public static boolean isUUID(String uuid){
        if (TextUtils.isEmpty(uuid)){
            return false;
        }

        return Pattern.matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", uuid);
    }

    public static boolean isUUID(String[] uuid) {
        if (uuid == null || uuid.length == 0){
            return false;
        }
        for (String s : uuid) {
            if (!StringUtils.isUUID(s)) {
                return false;
            }
        }

        return true;
    }

    public static String getMaskCardNumber(String str) {
        if (isEmpty(str)) return str;
        if (str.length() < 7) return "******";

        StringBuilder sb = new StringBuilder(str.length());
        sb.append(str.substring(0,4));
        sb.append("****");
//        for (int i = 4; i < str.length() - 4; ++i) {
//            sb.append("*");
//        }

        sb.append(str.substring(str.length() - 4));

        return sb.toString();
    }
}
